package cn.newgrand.netcall.offlinefiletransfer;

import java.awt.Component;
import java.util.List;

import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatRoomNotFoundException;

import cn.newgrand.common.NetcallUtil;
import cn.newgrand.smackx.packet.FileTransferCancel;

public class OfflineFileCancelListener implements PacketListener {

	@Override
	public void processPacket(Packet packet) {
		// TODO Auto-generated method stub

		FileTransferCancel cancel = (FileTransferCancel)packet;
//			StyledDocument doc = (StyledDocument)SparkManager.getChatManager().getChatContainer().getChatRoom(NetcallUtil.getBareJID(cancel.getFrom())).getTranscriptWindow().getDocument();
//			String aaa = doc.getText(doc.getStartPosition().getOffset(), doc.getEndPosition().getOffset()-1);
//			List<Integer>list = (List<Integer>)doc.getProperty(cancel.getFileName());
//			for(int a:list){
//				String b= doc.getText(a, cancel.getFileName().length());
//				doc.remove(a, cancel.getFileName().length());
//			}
			//Style style = doc.getStyle(cancel.getFileName());
			//Component c = StyleConstants.getComponent(style);
			//doc.removeStyle(cancel.getFileName());
			//StyleConstants.setComponent(style, null);
			//SparkManager.getChatManager().getChatContainer().getChatRoom(NetcallUtil.getBareJID(cancel.getFrom())).getTranscriptWindow().validate();
			//同步方法
			InnerPanelManager.getInstance().cancelTransfer(NetcallUtil.getBareJID(cancel.getFrom()), cancel.getFileName());
			IQ ret = IQ.createResultIQ(cancel);
			SparkManager.getConnection().sendPacket(ret);
	}

}
